#ifndef _COLSCATTER_H_
#define _COLSCATTER_H_

//
// This lookup table defines the line refresh order for a gadget with two panels mirrored across the axis, with their scanlines vertical.
// It only supports 128x64 panels with 1:32 multiplexing. It's used to distribute scanline updates evenly by area - outer columns need
// to be refreshed more frequently than inner columns in a rotating display to maintain a uniform density.
//
// In the ideal case, the panels would allow addressing of each scanline individually. The update strategy for a vertical rotating panel
// would then be to loop through every value up to the square of the column count, and update the column corresponding to the integer square
// root of the counter. The counter would be bit reversed, or incremented by some coprime value, to scatter the update evenly.
//
// In practice these panels update two scanlines simultaneously, half a screen apart. Since we want to update the outer columns more
// frequently than the inner columns, we need to scan out black on the inner columns during some of our updates. To come up with a refresh
// order that handles this constraint I ended up generating these lookup tables using simulated annealing with some terrible python code.
// The longer sequence uses the actual LED radii (1, 3, 5, 7) and the shorter one uses an approximation (1, 2, 3, 4). Visually I don't think
// you can tell the difference, so I ended up using the shorter sequence.
//
// In these tables, column indices below 32 update both scanlines, and indices above that only update the outer scanline.
//

/*
// 1 3 5 7 ... 127
static const uint8_t colscatter[] = {
29,36,44,27,33,31,53,15,11,23,62,48,39,32,56,54,52,57,49,60,58,19,38,8,42,50,61,37,63,34,46,59,45,41,62,12,53,55,47,24,52,26,28,36,22,16,35,25,43,63,17,51,18,29,39,33,42,30,32,27,38,40,46,55,58,20,21,56,45,47,31,5,44,41,28,54,34,57,48,61,4,51,49,62,50,59,43,42,26,35,23,39,14,24,63,52,
47,38,40,53,60,32,33,13,29,22,25,30,58,12,19,16,37,9,27,49,18,55,42,31,56,36,34,11,20,47,28,39,46,58,61,21,62,54,35,6,8,57,59,51,45,48,44,55,63,32,50,24,17,41,10,60,33,26,52,15,29,37,30,43,54,36,53,59,14,39,25,34,51,31,23,48,40,56,50,44,38,45,35,28,49,61,20,62,26,41,22,27,42,47,32,57,
21,63,43,46,19,55,36,24,37,39,16,60,33,18,29,44,58,30,52,34,40,49,13,59,54,57,31,38,53,47,41,35,55,42,60,56,61,46,11,58,48,19,62,52,32,39,36,50,12,27,25,63,22,37,17,53,45,28,61,23,8,33,26,24,15,41,34,30,20,10,6,51,14,48,31,57,59,43,35,18,54,29,39,60,21,49,44,58,45,4,55,56,62,32,37,40,
52,47,63,41,57,51,27,42,16,61,22,46,28,26,34,38,50,53,33,43,49,7,30,24,23,45,35,31,12,25,59,20,36,47,29,40,19,60,54,9,58,48,37,32,53,42,46,62,18,17,63,56,11,55,38,59,45,34,57,61,44,39,52,28,33,51,22,15,35,21,40,26,30,48,31,36,41,50,27,24,49,14,10,23,29,5,60,25,13,43,32,54,38,20,44,51,
62,53,63,58,39,47,2,16,56,59,40,50,61,60,49,35,55,33,41,46,57,36,54,45,42,30,52,31,43,19,53,37,56,61,58,44,28,27,38,48,47,18,32,55,17,39,8,22,25,34,62,63,46,52,41,45,29,21,24,35,42,36,33,59,11,26,28,19,23,12,48,50,57,49,37,31,15,30,6,40,22,20,61,39,53,14,56,45,32,41,27,34,60,10,51,43,
57,55,63,35,58,16,62,49,18,4,54,44,29,47,33,53,52,37,59,24,40,46,28,45,25,38,51,31,7,9,43,30,23,42,17,54,34,61,48,32,50,26,59,21,35,36,47,20,60,56,63,12,57,51,46,13,37,62,40,33,22,43,55,29,38,27,49,41,39,53,48,42,18,28,31,24,52,15,58,34,25,30,19,36,44,3,54,14,61,32,45,59,23,43,37,40,
53,60,63,56,17,50,16,41,38,62,33,57,20,39,47,10,54,26,29,44,51,27,55,46,36,34,31,56,28,21,45,11,35,50,30,8,49,37,25,48,52,58,32,61,41,22,47,59,55,38,44,63,24,19,60,42,39,46,33,53,62,57,18,43,58,36,13,52,29,17,40,34,48,27,23,31,37,35,15,28,22,41,56,44,51,30,57,26,53,32,6,14,50,42,61,20,
39,43,49,63,59,33,45,55,60,16,54,36,40,62,47,25,24,12,51,9,21,37,34,26,29,50,31,35,46,27,52,49,38,28,10,43,23,54,30,7,32,48,45,57,33,58,56,47,19,61,63,40,44,36,18,59,21,41,60,37,46,20,17,62,55,22,42,34,58,38,25,43,35,48,31,29,24,51,39,13,15,27,50,53,28,1,44,32,52,30,40,26,49,54,23,41,
14,36,57,63,42,61,56,37,16,11,51,60,38,59,62,50,47,53,34,52,58,45,35,39,55,54,44,31,49,25,29,56,46,60,8,33,42,62,41,19,26,48,27,32,50,52,21,36,43,5,47,55,63,38,22,61,28,45,57,24,30,39,17,58,12,46,34,42,35,59,51,20,18,40,48,23,31,9,54,53,33,29,15,43,62,26,25,28,56,4,13,32,38,46,37,49,
27,39,51,42,63,54,52,55,44,50,61,58,16,34,30,21,35,60,40,57,47,24,43,59,41,46,33,45,54,31,49,19,38,58,42,29,23,20,36,7,62,37,32,28,18,48,25,59,53,12,47,56,54,63,14,43,26,40,34,35,61,51,17,45,9,55,30,10,52,60,27,38,33,57,50,22,48,39,31,36,21,24,44,15,37,29,32,26,46,51,11,62,49,28,23,40,
13,59,41,25,20,34,63,3,42,50,56,53,38,16,61,58,22,47,44,39,60,19,30,33,55,36,46,27,49,43,31,57,37,52,45,56,41,8,29,53,58,32,18,60,54,48,34,42,62,47,55,44,6,35,59,63,19,39,25,17,24,14,52,61,26,28,43,21,36,45,33,54,41,50,30,37,23,48,40,31,27,15,57,44,51,10,34,29,56,32,49,60,20,39,38,53,
46,26,22,35,62,43,13,50,63,57,55,59,16,41,36,51,61,47,12,33,40,28,24,5,49,58,53,42,52,30,54,25,31,34,7,46,18,27,45,23,38,43,29,19,32,48,35,60,47,58,56,9,21,44,62,17,63,57,36,20,40,22,42,33,59,37,50,55,61,14,45,51,39,28,26,11,2,48,30,24,31,15,38,52,25,21,49,44,41,35,27,54,32,29,60,23,
42,50,40,58,51,36,46,62,63,13,56,37,52,33,16,39,57,53,47,61,59,49,60,11,22,55,44,34,38,58,41,18,31,30,19,42,56,35,45,52,8,61,46,32,25,53,28,27,48,37,36,55,47,17,26,39,63,22,43,62,33,24,12,29,50,20,41,45,57,10,6,19,21,59,34,14,23,28,40,48,31,35,30,54,15,49,37,26,61,32,56,43,57,4,39,51,
45,52,18,53,27,44,41,60,63,55,33,62,42,54,16,46,58,38,29,40,25,49,47,24,51,34,59,35,37,43,45,53,31,20,28,30,50,7,23,22,36,58,32,9,61,48,12,57,51,59,46,17,56,42,47,40,63,33,21,13,38,62,60,43,54,52,26,55,37,29,35,18,34,27,51,25,48,39,41,44,31,24,36,49,53,30,15,14,32,28,54,40,45,10,61,23,
11,20,19,26,59,38,50,57,33,63,37,56,16,3,62,53,44,60,49,41,22,39,47,29,34,55,46,58,36,52,45,27,31,8,43,25,50,56,42,30,19,60,21,32,48,37,38,17,61,44,55,58,33,22,47,41,35,63,59,52,57,46,24,39,62,28,13,18,34,53,43,51,36,29,40,23,26,48,49,54,42,31,44,5,57,15,27,6,30,20,56,41,60,32,14,53,
50,35,61,33,45,39,51,55,54,63,43,49,25,26,16,34,62,40,59,12,47,36,24,28,10,52,21,29,38,50,37,9,31,46,22,23,19,58,45,30,57,17,35,7,27,43,48,33,32,60,56,47,61,44,40,34,63,42,20,18,54,21,58,62,55,36,38,51,25,46,59,49,41,13,37,48,28,29,11,24,39,31,35,15,52,50,54,30,26,53,44,1,42,23,40,57,
27,32,51,34,60,49,38,61,14,56,63,16,45,41,36,52,62,58,50,22,47,53,37,55,39,11,59,25,60,42,44,35,19,29,31,17,56,8,33,46,30,52,48,38,58,2,45,50,32,55,21,41,27,28,47,57,22,36,63,61,43,42,24,39,5,62,12,20,46,19,26,17,35,48,23,40,18,59,33,38,13,53,25,31,29,28,15,34,30,9,56,42,22,43,32,51,
58,46,4,49,52,39,37,27,55,16,44,63,57,61,50,62,21,60,40,54,45,35,38,47,24,51,58,33,42,46,59,43,49,34,41,31,20,30,23,29,25,48,7,54,28,36,37,53,32,18,12,51,26,59,56,47,45,40,14,63,62,38,10,17,61,35,54,43,55,57,52,60,33,48,27,51,9,34,21,39,50,44,24,30,31,26,15,36,37,54,29,13,46,49,32,25,
40,23,28,19,59,38,11,20,42,53,16,62,56,63,3,58,22,50,41,44,61,39,47,33,34,60,57,55,49,46,27,45,37,36,30,53,52,31,56,8,58,43,19,48,6,29,18,32,42,60,44,41,22,55,47,25,35,59,62,39,17,63,21,24,26,52,14,45,34,33,61,51,28,37,43,48,50,40,36,57,54,23,30,44,27,31,15,38,41,53,10,56,49,32,20,29,
39,26,35,60,46,51,13,57,50,16,62,43,63,54,59,34,55,40,5,12,33,53,47,24,61,36,58,49,41,28,42,52,38,25,30,19,31,7,18,46,48,27,45,22,32,43,35,23,21,29,58,56,44,47,40,60,17,37,62,34,63,57,20,9,51,42,50,59,36,33,48,54,38,26,61,14,39,45,55,24,11,28,30,31,21,49,15,44,52,25,35,40,32,27,51,37,
50,41,58,29,42,54,2,16,60,56,62,63,23,46,36,13,53,39,52,33,38,49,57,47,59,61,44,11,58,19,18,60,8,56,31,30,22,35,55,41,48,37,42,32,52,53,45,61,46,34,25,27,17,26,28,39,47,36,63,24,62,43,12,6,50,55,54,33,19,29,20,40,21,48,41,57,45,59,10,35,37,31,14,49,30,28,26,56,32,15,34,23,51,39,61,43,
54,18,4,57,53,44,52,27,38,63,16,45,62,41,40,58,60,33,49,24,51,46,42,29,55,37,47,35,25,22,59,53,43,31,50,34,7,30,20,32,58,45,28,48,36,51,12,56,61,9,17,38,59,40,23,57,46,63,47,54,21,33,62,42,26,37,43,18,60,35,51,52,13,29,27,48,24,39,34,44,49,31,25,55,41,36,32,30,53,54,14,15,40,38,28,19,
26,50,61,11,59,56,20,10,37,63,33,16,45,57,3,62,49,23,44,53,39,60,22,41,34,58,47,29,46,27,56,50,36,31,8,52,43,32,38,19,30,25,55,48,60,45,21,17,42,37,44,58,61,33,35,59,24,63,47,22,41,39,18,46,52,62,57,28,55,34,43,51,40,53,36,48,26,49,29,13,6,31,27,44,32,5,56,42,54,57,15,30,20,50,23,60,
41,14,35,33,53,39,51,43,61,63,49,16,59,40,26,45,25,34,12,24,54,62,36,38,28,47,55,50,52,10,37,21,31,29,32,46,9,19,27,17,58,43,48,57,7,35,30,22,56,45,33,60,44,40,23,47,63,18,61,42,20,38,34,36,59,58,21,51,49,46,25,62,37,41,48,54,11,24,28,32,31,13,55,39,29,50,52,15,44,35,26,27,42,53,40,30,
1,57,49,51,38,60,56,54,14,63,16,36,34,41,61,23,52,37,45,50,58,62,59,47,53,11,44,39,60,25,42,56,32,17,31,19,22,35,46,8,29,55,48,62,52,38,33,58,50,27,21,28,41,45,47,36,24,57,34,63,43,5,42,12,30,61,55,46,39,17,20,22,26,48,19,59,18,40,35,32,38,53,28,31,25,56,15,13,33,62,9,29,23,54,42,46,
43,58,4,49,51,27,52,37,44,16,34,63,39,60,50,57,21,24,30,54,61,40,47,38,35,55,45,58,59,46,51,32,42,49,41,33,31,43,20,28,48,54,25,62,36,29,56,53,18,12,37,59,7,26,23,47,51,34,14,40,63,38,45,54,17,10,60,35,30,57,61,48,52,27,24,9,43,33,21,50,32,44,51,31,55,22,26,36,15,39,46,37,62,28,49,29,
25,40,13,56,59,38,34,16,20,53,42,63,19,50,41,3,58,23,44,11,30,60,33,47,61,22,46,57,56,49,27,39,32,36,37,53,31,45,8,52,48,58,55,18,62,60,6,51,44,29,41,42,34,54,24,25,47,59,43,35,63,14,21,17,33,26,55,28,30,52,39,45,48,50,61,40,37,36,57,44,32,19,54,27,56,31,41,38,15,53,23,62,10,60,49,46,
43,20,26,29,35,34,57,50,16,13,39,33,59,63,12,22,24,40,30,51,53,5,55,28,47,36,41,58,49,61,25,46,38,32,42,52,43,18,31,27,48,62,45,54,35,56,7,21,44,60,23,34,58,19,29,40,47,57,17,33,37,9,14,63,30,50,59,20,36,42,43,48,38,54,24,28,26,55,45,61,32,21,44,39,51,25,35,62,31,49,15,40,27,52,50,46,
2,41,60,56,37,58,22,16,11,29,42,23,53,33,36,30,38,63,57,13,51,44,52,59,49,60,18,47,56,39,58,61,8,46,32,35,55,48,41,62,53,43,31,22,37,34,25,42,28,52,27,45,19,24,61,26,17,6,12,50,36,55,47,33,30,14,63,48,21,39,57,40,54,43,20,41,29,59,28,35,56,45,10,32,37,49,23,26,62,18,34,19,31,15,57,38,
53,44,16,46,4,54,61,27,60,52,43,24,40,33,39,45,58,41,30,55,49,63,51,25,42,50,35,37,53,47,59,48,29,32,28,22,46,38,12,56,34,58,20,62,43,45,31,36,51,23,17,40,57,59,9,7,21,61,18,33,60,48,47,42,54,37,26,14,24,30,44,63,35,51,52,13,27,38,55,11,32,49,25,29,53,28,50,34,36,40,16,41,56,54,15,62,
31,39,51,46,26,10,44,59,33,20,37,23,60,45,61,57,49,53,43,50,38,56,3,48,63,30,22,19,32,58,8,47,41,36,27,46,60,55,52,44,29,34,42,39,25,24,21,17,45,18,31,37,62,48,43,58,33,51,28,6,59,55,35,22,47,14,61,52,40,57,44,41,32,36,56,63,53,50,30,49,26,16,42,13,60,39,23,27,34,51,43,5,29,54,57,20,
46,38,15,31,12,24,33,40,62,53,35,50,41,48,28,49,36,26,59,55,32,61,45,19,25,54,10,63,43,39,52,46,56,30,44,47,34,21,37,38,18,60,58,48,40,27,29,23,17,9,35,31,33,57,22,51,45,36,42,62,24,20,11,0,14,44,50,28,58,47,7,61,59,21,16,55,63,38,34,37,49,40,54,25,30,56,51,52,41,42,60,13,26,50,46,35};
*/

// 1 2 3 4 ... 63
static const uint8_t colscatter[] = {
44,32,49,41,54,36,47,59,29,51,43,60,21,33,8,26,38,25,48,18,37,30,31,55,14,10,20,24,45,22,34,61,35,27,49,12,39,28,58,51,47,41,53,57,63,62,36,11,50,32,40,16,23,6,54,61,56,33,59,52,58,46,37,60,13,17,42,19,31,25,30,44,21,15,35,39,34,41,50,29,54,55,26,27,43,48,24,40,28,36,63,20,38,62,57,49,14,
51,53,45,32,37,33,44,42,59,22,61,58,18,47,23,31,60,9,39,56,30,35,25,16,43,52,34,53,40,49,19,59,46,38,4,45,26,63,29,54,28,12,37,55,62,50,57,10,24,15,33,32,41,21,27,39,20,51,48,31,17,58,11,35,40,60,46,22,30,25,29,13,38,34,23,56,44,36,18,53,63,59,47,42,5,52,51,26,41,49,57,28,62,16,33,7,54,43,
61,32,14,8,24,31,55,3,53,45,50,58,27,38,44,57,52,19,30,60,15,34,36,42,49,22,29,48,63,41,37,56,43,58,21,39,23,46,33,25,50,59,62,40,28,45,20,32,35,51,12,47,31,54,38,17,26,29,48,24,42,36,53,2,43,30,57,55,9,60,27,18,46,37,39,52,63,13,58,40,19,22,1,56,47,44,35,29,16,62,49,32,21,28,25,6,10,11,
23,59,31,58,36,52,50,41,34,14,56,51,54,45,39,30,61,37,40,48,60,15,44,57,53,26,63,17,35,27,33,55,43,42,20,24,38,32,18,62,51,22,29,41,46,28,36,45,48,31,58,25,34,39,21,47,40,59,12,56,37,49,23,52,30,60,43,35,61,42,19,54,50,63,33,48,38,26,46,41,57,13,32,56,53,36,27,60,62,47,55,44,52,7,8,29,17,
34,31,51,37,22,43,58,16,18,42,24,35,25,28,14,41,30,45,59,21,38,55,63,33,20,61,15,44,32,4,54,51,26,40,49,60,39,48,50,56,11,57,62,63,5,10,34,27,23,46,53,29,45,9,35,58,52,54,60,38,47,19,44,31,33,48,24,50,30,17,40,25,36,43,32,39,59,61,58,55,28,21,42,46,22,37,13,20,63,34,51,62,41,47,56,48,18,
12,38,35,57,26,29,49,27,60,40,43,33,23,54,53,31,62,39,36,52,14,45,51,42,32,24,16,15,58,37,61,50,41,25,44,28,34,59,30,63,54,6,17,55,21,43,52,40,35,56,46,19,58,45,39,33,29,48,57,36,47,60,10,18,31,62,27,22,44,41,37,53,32,20,56,23,26,49,51,34,11,38,61,46,57,45,8,28,63,48,7,30,47,54,3,59,50,42,
53,24,36,33,44,58,52,51,55,9,29,25,60,17,37,31,46,43,13,62,32,54,38,34,16,15,27,21,40,39,56,18,61,26,51,60,42,20,12,23,63,57,35,36,49,30,14,41,22,33,45,43,53,37,61,47,48,24,28,19,58,27,38,50,39,31,34,40,32,52,25,62,44,42,49,23,29,53,54,46,45,60,36,43,41,56,35,26,47,51,63,48,59,5,33,18,30,
61,57,39,20,53,17,38,44,60,55,40,10,22,34,58,45,46,24,31,32,11,51,61,15,27,41,62,16,36,21,25,52,28,50,35,49,37,39,58,44,33,23,63,54,29,56,42,13,6,14,19,30,8,47,43,57,53,34,27,52,60,9,26,48,32,49,18,31,4,61,55,39,12,24,22,37,62,45,35,46,57,42,51,47,53,20,38,33,28,43,58,27,63,40,29,17,41,50,
55,16,2,56,30,44,25,54,7,36,45,46,21,32,52,47,19,42,37,31,26,59,61,28,49,35,43,23,38,50,62,24,48,41,57,33,40,44,22,53,52,46,45,15,39,63,29,34,27,36,51,49,10,26,28,56,30,55,18,37,11,32,25,48,53,38,41,20,54,44,35,61,31,47,14,59,13,40,49,56,60,58,33,19,39,42,23,30,36,50,57,43,21,34,52,16,29,
37,22,63,44,41,27,47,24,38,17,28,46,32,26,45,62,51,35,55,8,42,25,53,61,52,18,39,43,54,31,48,59,33,36,12,56,47,60,9,49,30,37,34,58,46,51,23,57,38,29,45,53,20,42,50,54,27,32,40,43,35,48,31,24,28,62,39,15,44,49,55,57,26,41,19,61,36,33,14,5,21,52,59,22,50,13,34,42,6,56,30,60,16,43,31,55,25,40,
47,17,29,44,58,32,3,7,51,41,27,52,46,54,53,18,62,56,36,45,37,28,23,10,48,33,57,61,31,11,47,38,49,26,34,44,59,40,20,54,19,30,24,46,41,21,55,39,60,50,35,32,45,29,48,63,25,42,47,37,36,58,27,49,43,62,22,52,12,55,38,56,51,1,46,28,53,8,34,61,41,18,31,48,45,59,57,39,15,30,26,35,42,23,17,52,0,54,
43,60,37,24,4,44,29,19,14,21,59,63,50,38,16,62,9,25,13,40,55,58,47,34,33,60,20,49,39,42,22,27,61,56,35,53,43,31,46,51,30,44,50,37,55,32,57,48,36,28,26,45,41,59,47,52,38,29,49,40,63,24,54,53,34,62,10,39,23,46,33,18,19,11,59,25,60,35,12,48,58,61,63,52,37,45,15,17,41,56,30,36,21,32,22,27,55,
40,6,50,46,42,51,31,28,29,34,7,25,26,20,16,62,43,44,47,45,24,33,59,35,49,37,23,53,54,41,50,63,61,14,60,51,8,62,36,42,57,38,58,52,32,48,47,27,56,39,13,34,44,55,43,29,31,17,50,30,21,22,28,5,46,19,35,33,9,25,40,26,59,20,42,47,24,63,48,61,23,38,36,62,45,18,49,12,60,39,53,32,54,11,34,46,27,51,
57,63,58,37,52,29,40,15,56,55,30,41,35,16,10,50,28,33,49,59,45,38,31,21,22,44,61,46,25,36,26,19,43,39,62,20,23,24,2,32,47,40,59,50,63,48,37,28,61,17,42,54,57,41,53,35,13,14,55,30,51,38,44,26,33,27,63,52,56,43,29,36,50,60,39,47,48,57,54,40,49,55,34,62,42,21,37,31,59,51,32,46,58,45,9,61,3,
24,20,28,12,18,25,6,55,22,11,16,30,15,49,59,63,33,7,4,8,19,53,26,29,42,60,56,46,52,57,23,34,45,37,50,41,62,27,54,31,44,48,32,35,17,43,58,60,38,61,47,51,56,21,57,55,40,52,39,59,30,14,10,33,36,50,22,31,13,28,58,48,49,41,29,37,44,34,24,25,55,59,19,43,53,62,20,15,38,35,63,54,32,40,26,60,61,18,
46,42,39,49,16,27,57,56,23,45,36,33,30,51,41,12,31,21,54,52,5,61,28,58,11,34,47,59,50,38,57,40,49,56,55,35,62,14,48,42,63,51,32,22,29,39,53,13,60,59,26,20,44,36,25,9,50,33,24,55,17,30,43,15,31,37,40,38,54,19,61,27,34,16,53,28,46,58,42,35,57,50,45,52,23,7,62,56,63};

#endif
